Player = function()
{
  this.so;
  this.conf;
  this.track = {
  	info: {},
  	current:null,
  	to_remove:false
  };
  
	this.is_playlist = false;
	
  window.player = this;
}
Player.prototype.write = function (htmlelement)
{
    this.so.write(htmlelement);
    //if(this.is_playlist)
    	//this.loadFile({title:this.track.info.title+' - '+this.track.info.artist+' - '+this.track.info.release,id:''+this.track.info.id+''});
}
Player.prototype.configure = function (conf)
{

  this.conf = (conf  instanceof Object)?conf:{};
  var def = {
  	  javascriptid: 'mt_player',
      playersrc: 'player/mymp3player.swf',//'http://musictalk.helloweb.eu/player',
      repeat:'list',//'list'
      autostart: false,
      shuffle:false,
      width:'410',
      height:'20',
      displayheight:'0',
      src:null,
      frontcolor: '0x93C6D3',
      backcolor: '0x000000',
      backgroundcolor: '0xFFFFFF',
      lightcolor: '0xFFFFFF',
      autoscroll:false,
      showeq:true,
      enablejs:false,
      allowfullscreen:false,
      allowscriptaccess:true,
      screencolor: '0x336699',
      callback: null,
      id:null
  
    };
    
    // fill in the missing user param with default values
    for (k in def)
      if ((typeof(this.conf[k]) != typeof(def[k])) && def[k] != null) 	this.conf[k] = def[k];
  
    this.so = new SWFObject(this.conf['playersrc'],'mt_player',this.conf['width'], this.conf['height'], '7', this.conf['backgroundcolor']);
  	this.so.addVariable('javascriptid',this.conf['javascriptid']);
    this.so.addParam('allowfullscreen',(this.conf['allowfullscreen']?'true':'false'));
    this.so.addParam('allowscriptaccess',(this.conf['allowscriptaccess']?'true':'false'));
    this.so.addVariable('file',this.conf['src']);
    this.so.addVariable('height',this.conf['height']);
    this.so.addVariable('width',this.conf['width']);
    this.so.addVariable('displayheight',this.conf['displayheight']);
    this.so.addVariable('frontcolor',this.conf['frontcolor']);
    this.so.addVariable('backcolor',this.conf['backcolor']);
    this.so.addVariable('lightcolor',this.conf['lightcolor']);
    this.so.addVariable('screencolor',this.conf['screencolor']);
    this.so.addVariable('autostart',(this.conf['autostart']?'true':'false'));
    this.so.addVariable('showeq',(this.conf['showeq']?'true':'false'));
    this.so.addVariable('enablejs',(this.conf['enablejs']?'true':'false'));
    this.so.addVariable('shuffle',(this.conf['shuffle']?'true':'false'));
    this.so.addVariable('repeat',this.conf['repeat']);
    if(this.conf['callback']) this.so.addVariable('callback',this.conf['callback']);
    if(this.conf['id']) this.so.addVariable('id',this.conf['id']);
  
   return this;
}

Player.prototype.removeItem = function (position)
{
    var p = $(this.conf.javascriptid);
    if(p) p.removeItem(position?position:this.track.info.position);
    else throw "No id for the player was specified!";
}
Player.prototype.setTrackInfo = function(info)
{
	this.track.info = $merge(this.track.info,info);
}
Player.prototype.loadFile = function(file_obj)
{
	var p = $(this.conf.javascriptid);
  
  if(p) {
  	var file2load = {
  										file:file_obj['file']?file_obj['file']:this.conf.src,
  										title : file_obj.title+' - '+file_obj.artist+' - '+file_obj.release,
  										id: file_obj['id'].toString()
  									}
  	p.loadFile(file2load);
  }
  else throw "No id for the player was specified!";
}
Player.prototype.getSrc = function()
{
	return this.conf.src;
}
Player.prototype.track_to_remove = function()
{
	return this.track.is_playlist && this.track.info.position != null && this.track.to_remove;
}

Player.prototype.is_new_track = function()
{
	return this.track.info.id != null && this.track.info.id == this.track.current;
}